<?php

global $confirmType;
global $actionType;
global $organizationType;
	$year= date('Y');
	$month= date('m');
	$date= date('d');
	
//return;
?>
	<div class="block">

	<div class="invertedshiftdown">
<ul>
	<?php
	if($organization->type=='s'){
	?>
			<li><a href="?page=organization_inventory&id=<?php echo $organization->id; ?>">查看货存</a></li>
			<li><a href="?page=organization_sell&id=<?php echo $organization->id; ?>">出售</a></li>
			<li><a href="?page=organization_return&id=<?php echo $organization->id; ?>">退款</a></li>
			<li><a href="?page=organization_distribute&id=<?php echo $organization->id; ?>">分配</a></li>
			<li><a href="?page=organization_distribute_confirm&id=<?php echo $organization->id; ?>">处理待定分配</a></li>
			<li><a href="?page=organization_transaction&id=<?php echo $organization->id; ?>">查看物流记录</a></li>
			<li class="current"><a href="?page=organization_sell_record&id=<?php echo $organization->id; ?>">查看销售记录</a></li>
	<?php
	}elseif($organization->type=='w'){
	?>
	       	<li><a href="?page=organization_inventory&id=<?php echo $organization->id; ?>">查看库存</a></li>
			<li><a href="?page=organization_stack&id=<?php echo $organization->id; ?>">入库</a></li>
			<li><a href="?page=organization_distribute&id=<?php echo $organization->id; ?>">分配</a></li>
			<li><a href="?page=organization_distribute_confirm&id=<?php echo $organization->id; ?>">处理待定分配</a></li>
			<li><a href="?page=organization_transaction&id=<?php echo $organization->id; ?>">查看物流记录</a></li>
			
    <?php
	}
	?>
</ul>




<form id="myform">
<input type="text" class="textinput" /> <input class="submit" type="submit" value="搜索" />
</form>
</div>

<br style="clear: both;" />
<div id= 'content'>

	<div id="message">
		<h4><?php echo $message ?></h4><?php echo $condition ?>
	</div>
		<h2><?php echo $organization->name ?>》销售记录显示</h2>
	
	<table class="contentTable" border="1">
			<tbody><tr class="solid">
		<td>记录号</td>
		<td>种类</td>
		<td>来自</td>
		<td>目标</td>
		<td>状态</td>
        <td>发起用户</td>
		<td>确认用户</td>
		<td>扫描条码</td>
		<td>金额</td>
		<td>数目</td>
		<td>发起时间</td>
		<td>结束时间</td>

		</tr>
	
	
		<?php
		//global $auth;
		//print_r($auth);
		  //  global $organizationType;
			//		print_r($organizationType);
			$totalNumber=0;$totalReturnNumber=0;$totalSoldNumber=0;
			$totalAmount=0;$totalReturnAmount=0;$totalSoldAmount=0;
		foreach($organization->getTransactions() as $trans){
			
    	$id=$trans->id;
		$action=$trans->action;
    	$source=$trans->source;
    	$target=$trans->target;
    	$confirm=$trans->confirm;
    	$user1=$trans->user1;
    	$user2=$trans->user2;
	    $scan_code=$trans->scan_code;
    	$amount=$trans->amount;
    	$income=$trans->income;
	   $begin_time_stamp=$trans->begin_time_stamp;
	   $finish_time_stamp=$trans->finish_time_stamp;
		$mark="";$moneyMark="";
			 if($action=="consume"||$action=='distribute'||$action=="sell"){
                 $mark="-";
				 $moneyMark="+";
			 }else{
			 	$mark="+";
				$moneyMark="-";
				
			 }
			 if($confirm=='1'){
			 	if($action=="sell"){
			 		$mark="-";
				 $moneyMark="+";
			 		$totalAmount=$totalAmount+$income;
					$totalNumber=$totalNumber-$amount;
					$totalSoldAmount=$totalSoldAmount+$income;
					$totalSoldNumber=$totalSoldNumber+$amount;
			 	}else{
			 		$mark="+";
				$moneyMark="-";
			 		$totalAmount=$totalAmount-$income;
					$totalNumber=$totalNumber+$amount;	
					$totalReturnAmount=$totalReturnAmount+$income;
					$totalReturnNumber=$totalReturnNumber+$amount;
			 	}
			 }
		?>
		<tr>
		<td><?php echo $id?></td>
		<td><?php echo $actionType[$action]?></td>
		<td><?php echo $source ?></td>
		<td><?php echo $target ?></td>
		<td><?php 
		    if($confirm=='0'){
		    ?>
			<div class="important">
				<?php
			}elseif($confirm=='1'){
				
				?>
							<div class="normal">

				<?php
			}else{
				?>
							<div class="greyout">

				<?php
			}
				?>
			<?php echo $confirmType[$confirm] ?>
			</div></td>
		<td><?php echo $user1 ?></td>
		<td><?php echo $user2 ?></td>
		<td><?php echo $scan_code ?></td>
		<td><?php echo $moneyMark.$income ?></td>
		<td><?php echo $mark.$amount ?></td>
		<td><?php echo $begin_time_stamp ?></td>
		<td><?php echo $finish_time_stamp ?></td>

		</tr>

	
	<?php
		}

	?>
	</tbody></table>
	<br><br>
	<table style="float:right; padding-right:50px"><tbody>
		<tr class="solid">
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		<td></td>
		<td>总售出件数</td>
		
		<td>总退还件数</td>
		
        <td>净售出件数</td>
		
		<td>总收入额</td>
		
		<td>总退款额</td>
		
		<td>净收入额</td>

		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		<td></td>
		<td><?php
		echo $totalSoldNumber;
		?></td>
		
		<td><?php
		echo $totalReturnNumber;
		?></td>
        <td><?php
		echo 0-$totalNumber;
		?></td>
		<td><?php
		echo $totalSoldAmount;
		?></td>
		<td><?php
		echo $totalReturnAmount;
		?></td>
		<td><?php
		echo $totalAmount;
		?></td>

		</tr>
		</tbody></table>
		<h4>按条件搜索</h4>
		 <form action="" method="post">

        	
            <div class="element">
             <label class="form">扫描条码</label>
             <input type="text" id="scan_code" name="scan_code" class="text" maxlength="14" size="14"><div class="important">若为空，搜查结果会显示全部条形码</div>
            </div>

             <div style="clear:both;">
             	            <div class="element">

             <label class="form">交易日期</label>
 </div>
  <li>
<label>
从
</label>
<span>
	
	
	
<select name="fromYear">
	<?php
	for($i = 2009; $i <= 2020; $i++){
		if($year==$i){
		 echo "<option value='$i' selected>$i</option>";
		}else{
		 echo "<option value='$i'>$i</option>";		
			
		}
	}
	?>
</select>
 <label for="Field103">年</label>
</span>
<span class="symbol">/</span>
<span>
<select name="fromMonth">
	<?php
	for($i = 1; $i <= 12; $i++){
		if($i<10){
	   		$i="0".$i;
		}
	 if($month==$i){
		 echo "<option value='$i' selected>$i</option>";
		}else{
		 echo "<option value='$i'>$i</option>";		
		}
	}
	?>
</select><label for="Field103-1">月</label>
</span> 
<span class="symbol">/</span>
<span>
<select name="fromDate">
	<?php
   for($i = 1; $i <= 31; $i++){
   	if($i<10){
	   		$i="0".$i;
		}
	   if($date==$i){
		 echo "<option value='$i' selected>$i</option>";
		}else{
		 echo "<option value='$i'>$i</option>";		
		}
	}
	?>
</select>
<label for="Field103-2">日</label>
</span>



</li>

  <li>
<label>
到
</label>
<span>
	

<select name="toYear">
	<?php
	for($i = 2009; $i <= 2020; $i++){
		if($year==$i){
		 echo "<option value='$i' selected>$i</option>";
		}else{
		 echo "<option value='$i'>$i</option>";		
			
		}
	}
	?>
</select>
 <label for="Field103">年</label>
</span>
<span class="symbol">/</span>
<span>
<select name="toMonth">
	<?php
	for($i = 1; $i <= 12; $i++){
		if($i<10){
	   		$i="0".$i;
		}
	 if($month==$i){
		 echo "<option value='$i' selected>$i</option>";
		}else{
		 echo "<option value='$i'>$i</option>";		
			
		}
	}
	?>
</select><label for="Field103-1">月</label>
</span> 
<span class="symbol">/</span>
<span>
<select name="toDate">
	<?php
	for($i = 1; $i <= 31; $i++){
		if($i<10){
	   		$i="0".$i;
		}
	   if($date==$i){
	   
		 echo "<option value='$i' selected>$i</option>";
			
		}else{
		
		 echo "<option value='$i'>$i</option>";		
		}
	}
	?>
</select>
<label for="Field103-2">日</label>
</span>



</li>
   </div>
                <div style="clear:both;">

    <div class="element">
             <label class="form">最小金额</label>
             <input type="text" id="scan_code" name="minimal" class="text" size="14"><div class="important">若为空，搜查结果会无最小金额限制</div>
            </div>
   <div style="clear:both;">

    <div class="element">
             <label class="form">最大金额</label>
             <input type="text" id="scan_code" name="maximal" class="text" size="14" ><div class="important">若为空，搜查结果会无最大金额限制</div>
            </div>
   <br>
   <div class="element">
<input type="submit" value="递交" />
        <div class="loading"></div>
    </div>
    </form>

<br>
<br>
<br>


   
<div class="clear"></div>
	</div>